package com.api.oa.mapper;


import com.api.oa.model.entity.OaMessage;
import com.api.oa.model.entity.OaOrgClassify;
import com.api.oa.model.vo.OaMessageVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
@Mapper
public interface OaMessageMapper {


    @Insert("insert into oa_message (" +
            "content," +
            "messageFrom," +
            "messageTo," +
            "messageAt," +
            "messageType" +
            ") " +
            "values " +
            "(" +
            "#{business.content}," +
            "#{business.messageFrom}," +
            "#{business.messageTo}," +
            "#{business.messageAt}," +
            "#{business.messageType}" +
            ")" )
    @Options(useGeneratedKeys = true,keyProperty = "messageId",keyColumn = "id")
    Integer insert(@Param("business") OaMessage business);


    @Update("update oa_message set " +
            "classifyName = #{org.classifyName}, " +
            "classifyPid=#{org.classifyPid} " +
            "where messageId = #{org.classifyId}")
    Integer update(@Param("org") OaMessage org);


    @Delete("delete from oa_message where messageId=#{id}")
    void delete(@Param("id") Long id);




    @Select("select * from oa_message left join oa_org on oa_message.messageFrom = oa_org.orgUserId  where messageId = #{id} limit 1")
    OaMessageVO findOne(@Param("id") Long id);


    @Select("select * from oa_message left join oa_org on oa_message.messageFrom = oa_org.orgUserId where messageFrom=#{messageFrom} and messageTo = #{messageTo} or (messageFrom=#{messageTo} and messageTo = #{messageFrom})")
    List<OaMessageVO> list(@Param("messageFrom") String from, @Param("messageTo") String to);
}
